home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / GAME / RoboWar 4.1.1.sit / RoboWar 4.1.1 / RoboWar 4.1.1.rsrc / TEXT_2004_Operators.txt < prev    next >
Text File  |  1995-04-29  |  16KB  |  226 lines

  1. IV:  Operators
  2.  
  3. This section lists each operator.  It gives the name and the effect it has on the stack or robot state.  The operands are as follows:
  4.  
  5. +          -          *          /          =
  6. !          <          <          ABS        AND
  7. ARCCOS     ARCSIN     ARCTAN     BEEP       CALL       
  8. CHS        COS        DEBUGGER   DIST       DROP       
  9. DROPALL    DUPLICATE  FLUSHINT   ICON0-9    IF         
  10. IFE        IFEG       IFG        INTOFF     INTON      
  11. JUMP       MAX        MIN        MOD        NOP
  12. NOT        OR         PRINT      RETURN     ROLL       
  13. RTI        SETINT     SETPARAM   SIN        SND0-9
  14. STORE      SQRT       SWAP       SYNC       TAN
  15. VSTORE     VRECALL    XOR
  16.  
  17. A number of these commands have abbreviations:  DUP is an acceptable substitute for DUPLICATE, STO for STORE, DEBUG for DEBUGGER, COSINE for COS, SINE for SIN, TANGENT for TAN, and EOR for XOR.  RETURN and JUMP really perform the same function, as noted below; hence, in the debugger, both instructions are listed as JUMP.  In the debugger, the special (RECALL) and (END) operators may appear; these are inserted by the Assembler and not used directly by the programmer.
  18.  
  19. +
  20. Adds the top two numbers on the stack, removes them, and replaces them with the result.
  21. Ex: 窶œ4 5 +窶 leaves 9 on the top of the stack.
  22.  
  23. -
  24. Subtracts the top number from the second number on the stack, removes them, and replaces them with the result.
  25. Ex: 窶œ9 3 -窶 leaves 6 on the top of the stack.
  26.  
  27. *
  28. Multiplies the top two numbers on the stack, removes them, and replaces them with the result.
  29. Ex: 窶œ2 4 *窶 leaves 8 on the top of the stack.
  30.  
  31. /
  32. Divides the second number by the top number on the stack, removes them, and replaces them with the result.
  33. Ex: 窶œ22 3 /窶 leaves 7 on the top of the stack.  (7.3333 is truncated to 7)
  34.  
  35. =
  36. Checks if the top two numbers on the stack are equal, then removes them.  If they are equal, it places a 1 on the stack, otherwise it pushes a 0.
  37. Ex: 窶œ2 2 =窶 leaves a 1 on the stack.
  38.  
  39. !
  40. Checks if the top two numbers on the stack are not equal, then removes them.  If they are not equal, it places a 1 on the stack, otherwise it pushes a 0.  (The symbol ! comes from the logical NOT command in the language C.)
  41. Ex: 窶œ5 5 !窶 leaves a 0 on the stack.
  42.  
  43. >
  44. Checks if the second number on the stack exceeds the top number, then removes them.  If the second number is greater, it places a 1 on the stack, otherwise it pushes a 0.
  45. Ex: 窶œ5 4 >窶 leaves a 1 on the stack.
  46.  
  47. <
  48. Checks if the second number on the stack is less than the top number, then removes them.  If the second number is less, it places a 1 on the stack, otherwise it pushes a 0.
  49. Ex: 窶œ7 3 <窶 leaves a 0 on the stack.
  50.  
  51. ABS
  52. Absolute Value.  Removes the top argument and returns its absolute value.
  53. EX:  窶œ-8 ABS窶 leaves 8 on the stack.
  54.  
  55. AND
  56. Checks if the top two numbers on the stack are both not zero, then removes them.  If they are both not zero, it places a 1 on the stack, otherwise it pushes a 0.
  57. EX: 窶œ2 3 AND窶 leaves a 1 on the top of the stack.
  58.  
  59. ARCCOS
  60. Inverse Cosine.  Computes the principal inverse cosine of the top number divided by the second number.  Returns the result in degrees in the range of 0 to 180 (just like the C library routine).  Note that you may have to convert the result to the appropriate coordinate system before using it to set your AIM register or such.
  61. EX:  窶œ1000 707 ARCCOS窶 leaves 45 on the stack.
  62.  
  63. ARCSIN
  64. Inverse Sine.  Computes the principal inverse sine of the top number divided by the second number.  Returns the result in degrees in the range of -90 to 90 (just like the C library routine).  Note that you may have to convert the result to the appropriate coordinate system before using it to set your AIM register or such.  
  65. EX:  窶œ1000 707 ARCSIN窶 leaves 45 on the stack.
  66.  
  67. ARCTAN
  68. Inverse Tangent.  Computes the inverse tangent of the ratio of the top two numbers.  The y value must be the top operand; the x value must be the second operand.  ARCTAN removes the top two operands and returns the arctangent of y/x.  The result is in degrees between 0 and 359, with 0 degrees pointing up, just as with AIM angles.  Also remember that the positive x values are on the right side of the arena, while positive y values are on the bottom of the arena.
  69. EX:  窶œ-5 0 ARCTAN窶 leaves 270 on the stack.
  70.  
  71. BEEP
  72. Beeps once.  Most useful in debugging a robot.
  73. EX: 窶廝EEP窶 leaves nothing on the stack.
  74.  
  75. CALL
  76. Jumps to the instruction number specified by the top element of the stack, removes the top element, places the return address (the instruction number previously being executed) on the top of the stack, and resumes execution at the new instruction.  Very similar to JUMP, but leaves the return address on the stack.
  77.  
  78. CHS
  79. CHange Sign.  Multiplies the top operand on the stack by -1, removes it, and returns the result on the stack.
  80. EX: 窶œ3 CHS窶 leaves -3 on the stack.
  81.  
  82. COS or COSINE
  83. Cosine function.  The top argument should be the hypotenuse and the second argument should be the angle.  COS removes the top two arguments and returns the hypotenuse times the cosine of the angle, truncated to an integer value.  The angle must be between 0 and 359 or the result is undefined.  Also, note that while 0 degrees is pointing straight up on the turret, the cosine of 90 degrees is still 0 (e.g. COS uses the standard trig coordinate system).
  84. EX: 窶œ30 100 COS窶 leaves 86 (=100*cos(30) on the stack.
  85.  
  86. DEBUG/DEBUGGER
  87. A hook for debugging.  If the robot is selected for debugging (i.e. has the bug icon beside it in the Arena display), tthis command acts as a sync instruction, pausing until the end of the chronon (because the debugger cannot turn on in the middle of a chronon).   Execution pauses immediately after the debugger instruction and one can use the debugger facilities.  If the robot is not selected for debugging, nothing happens and no time is used (so that one can run accurate timing on a robot without having to remove DEBUG statements).
  88. EX:  "DEBUGGER" pauses until the end of chronon and enters the debugger if debugger is on
  89.  
  90. DIST
  91. Calculate the distance from the origin to some point (x,y) = Sqrt(x*x+y*y).  The top two elements of the stack are x and y; they are removed and replaced with the distance.
  92. EX:  窶œ10 10 DIST窶 leaves 14 on the stack.
  93.  
  94. DROP
  95. Drops the top element from the stack.
  96. EX: 窶œ5 DROP窶 leaves nothing on the stack.
  97.  
  98. DROPALL
  99. This command drops everything off of the stack.  It is useful for interrupt routines that may not return to where they were called, thus leaving an unknown amount of junk on the stack.  It is also useful for sloppy programmers who let junk accumulate on the stack and run into stack overflows after lots of chronons.
  100. EX:  窶œ87 42 99 -32 DROPALL窶 leaves absolutely nothing on the stack.
  101.  
  102. DUPLICATE or DUP (either token is allowed)
  103. Duplicates the number on the top of the stack.
  104. EX: 窶œ5 DUP窶 leaves 5 on the top of the stack and 5 in the second position.
  105.  
  106. FLUSHINT
  107. Removes all pending interrupts from the interrupt queue.
  108. EX:  窶廡LUSHINT窶 does nothing to the stack.
  109.  
  110. ICON0-9
  111. Sets the robot's icon.  ICON0 is special; it causes the robot to display icon #0 if shields are off, but icon #1 if shields are on.  Other ICONx commands display icon #x.  Takes zero chronons to execute.  The various icon commands are used for icon animation.
  112. EX:  窶廬CON3窶 does nothing to the stack but makes the robot display icon #3.
  113.  
  114. IF
  115. Checks the second operand on the stack.  If it is not zero then it leaves the return address on the stack and jumps to the label specified on the top of the stack.  In any case, it removes the second operand and the destination label from the stack.
  116. EX: 窶œ1 MySub IF窶 jumps to the subroutine MySub and leaves the return address on the stack.
  117.  
  118. IFE
  119. Stands for IF-THEN-ELSE.  Checks the third operand on the stack.  If it is not zero than it leaves the return address on the stack and jumps to the label specified in the second position on the stack.  If it is zero then it leaves the return address on the stack and jumps to the label specified on the top of the stack.  In any case it removes the first, second, and third elements from the stack.
  120. EX: 窶œ0 SubA SubB IFE窶 jumps to the subroutine SubB and leaves the return address on the stack.
  121.  
  122. IFG
  123. Stands for IF-GOTO.  Checks the second operand on the stack.  If it is not zero then it jumps to the label specified on the top of the stack without leaving a return address.  In any case, it removes the second operand and the destination label from the stack.
  124. EX: 窶彝ANGE TARGETING IFG窶 jumps to the label TARGETING if a hostile robot is in the line of fire and leaves nothing on the stack.
  125.  
  126. IFEG
  127. Stands for IF-THEN-ELSE-GOTO.  Checks the third operand on the stack.  If it is not zero than it jumps to the label specified in the second position on the stack.  If it is zero then it jumps to the label specified on the top of the stack.  Unlike IFE, it leaves no return address.  In any case it removes the first, second, and third elements from the stack.
  128. EX: 窶œ0 SubA SubB IFEG窶 jumps to the subroutine SubB, leaving nothing on the stack
  129.  
  130. INTOFF
  131. Turns interrupts off until next INTON command.
  132. EX:  窶廬NTOFF窶 does nothing to the stack.
  133.  
  134. INTON
  135. Turns interrupts on.  Must be used near start of any robot that uses interrupts.
  136. EX:  窶廬NTON窶 does nothing to the stack.
  137.  
  138. JUMP
  139. Jumps to the instruction number specified by the top element of the stack, removes the top element, and resumes execution at the new instruction.  This is the same operation as RETURN.
  140.  
  141. MAX
  142. Leaves only the greater of the top two numbers on the stack.
  143. EX:  窶œ4 8 MAX窶 leaves 8 on the stack.
  144.  
  145. MIN
  146. Leaves only the lesser of the top two numbers on the stack.
  147. EX:  窶œ4 8 MIN窶 leaves 4 on the stack.
  148.  
  149. MOD
  150. Performs a modulus operation (remainder of integer division) on the top two elements of the stack.  Removes them and returns the result on the stack.  Note that this follows the same rules as the modulus operation in C; for example, -69 mod 360 = -69.
  151. EX: 窶œ10 3 MOD窶 leaves 10 mod 3 = 10-3*Trunc(10/3) = 1 on the stack.
  152.  
  153. NOP
  154. No OPeration.  Does nothing whatsoever, except take up time and space.  May be used when some timing loop is necessary.
  155. EX: 窶廸OP窶 leaves nothing on the stack.
  156.  
  157. NOT
  158. Logical Not.  Checks top operand, removes it.  Returns 1 if it was 0, 0 otherwise.
  159. EX: 窶œ4 NOT窶 leaves 0 on the stack.
  160.  
  161. OR
  162. Checks if either of the top two numbers on the stack is not zero, then removes them.  If either is not zero, it places a 1 on the stack, otherwise it pushes a 0.
  163. EX: 窶œ0 4 OR窶 leaves a 1 on the top of the stack.
  164.  
  165. PRINT
  166. Displays the top element of the stack in a dialog box.  Takes zero chronons to execute.  Intended for debugging purposes only.
  167. EX:  窶œ5 PRINT窶 leaves 5 on the stack and displays a dialog box reading 窶œ5窶
  168.  
  169. RETURN
  170. Jumps to the instruction number specified by the top element of the stack, removes the top element, and resumes execution at the new instruction.  The same operator, usually written with the name RETURN, returns after a subroutine call made by IF or CALL by jumping to the return address that the IF or CALL left on the top of the stack.
  171.  
  172. ROLL
  173. Rolls the second element of the stack back the number of places specified by the top operand, then removes the top operand.
  174. EX: 窶œ1 2 3 4 5 2 ROLL窶 rolls 5 back 2 places, leaving 1 2 5 3 4 on the stack.
  175.  
  176. RTI
  177. Returns from interrupt.  First enables interrupts like INTON, then pops return address from top of stack and jumps there like RETURN.
  178. EX: 窶彝TI窶 removes return address from stack.
  179.  
  180. SETINT
  181. Sets an interrupt procedure to execute when interrupt occurs and interrupts are enabled.  The top of the stack must have the name of the register corresponding to the interrupt (choices are COLLISION, WALL, DAMAGE, TOP, BOTTOM, LEFT, RIGHT, RADAR, RANGE, and SIGNAL).  The second item on the stack must be the address of a routine that handles the interrupt.
  182. EX:  窶徘anicsub RADAR' SETINT窶 leaves nothing on the stack.
  183.  
  184. SETPARAM
  185. Sets a parameter controlling when interrupts occur.  The top of the stack must have the name of the register corresponding to the interrupt.  The second item on the stack is the value to which the parameter will be set.  Note that COLLISION and WALL ignore their parameters.  The remaining default parameters are 150 for DAMAGE, 20 for TOP, 280 for BOTTOM, 20 for LEFT, 280 for RIGHT, 600 for RADAR and RANGE, and 0 for SIGNAL.  SETPARAM may also be used to set information for the PROBE and HISTORY registers.
  186. EX:  窶œ100 RANGE' SETPARAM窶 leaves nothing on the stack.
  187.  
  188. SIN or SINE
  189. Sine function.  The top argument should be the hypotenuse and the second argument should be the angle.  Sine removes the top two arguments and returns the hypotenuse times the sine of the angle, truncated to an integer value.  The angle must be between 0 and 359 or the result is undefined.  Also, note that while 0 degrees is pointing straight up on the turret, the sine of 0 degrees is 0 (e.g. sin uses the standard trig coordinate system).
  190. EX: 窶œ30 100 SIN窶 leaves 50 (=100*sin(30) on the stack.
  191.  
  192. SND0-9
  193. Plays a sound defined in the Recording Studio.  SNDx plays sound #x defined in the Recording Studio.   Takes zero chronons to execute.  The various other SND commands are used to enliven a robot with sound effects and to waste ungodly amounts of disk space.
  194. EX:  窶彜ND2窶 does nothing to the stack but plays sound #2.
  195.  
  196. STO or STORE (either token is allowed)
  197. Stores the second number on the stack in the variable specified at the top of the stack, and removes both the number and variable reference.  The operand on the top of the stack must be a quoted variable or an error is reported.  Also see the section on variables below, as values cannot be stored in some variables, such as RANGE.
  198. EX: 窶œ20 aim窶™ store窶 stores 20 in the variable AIM and leaves nothing on the stack.
  199.  
  200. SQRT
  201. Square root function.  Removes the top argument and returns its square root, truncated to an integer.  If the argument is less than zero, an error results and the robot self-destructs.
  202. EX: 窶œ10 SQRT窶 leaves 3 on the stack.
  203.  
  204. SWAP
  205. Swaps the top and second elements on the stack.
  206. EX: 窶œ1 2 SWAP窶 leaves 1 at the top of the stack and 2 in the second position.
  207.  
  208. SYNC
  209. Ceases execution of code until the end of chronon.  The next instruction will be executed at the next chronon.  Has no effect on the stack.
  210.  
  211. TAN or TANGENT
  212. Like SIN and COS, but computes the tangent function.  If the result is greater than 19999 it is clipped to 19999; if the result is less than -19999, it is clipped to -19999.
  213.  
  214. VSTORE
  215. Store a element in a vector (1 dimensional array).  The top element specifies the element of the vector (1 to 100) while the second element is the number to store.  Both arguments are removed from the stack.
  216. EX:  窶œ42 1 VSTORE窶 stores 42 in the first element of the vector.
  217.  
  218. VRECALL
  219. Returns the nth element of the vector.  The top of the stack holds the element to reference; it is removed and replaced by the contents of the vector.  Uninitialized vector elements default to zero.  If the element number is less than 1 or greater than 100, zero is also returned.
  220. EX:  窶œ1 VRECALL窶 leaves 42 on the stack assuming the previous example was last executed.
  221.  
  222. XOR or EOR (either token is allowed)
  223. Exclusive OR.  Checks if the top or second item on the stack, but not both, are nonzero, then removes them.  If so, it places a 1 on the stack; otherwise it pushes a 0.
  224. EX:  窶œ1 1 XOR窶 leaves a 0 on the top of the stack.
  225.  
  226.